package com.wskj.common.config;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * 读取项目相关配置
 *
 * @author ruoyi
 */

@Data
@NoArgsConstructor
@Accessors(chain = true)
@Component
@ConfigurationProperties(prefix = "wskj")
public class RuoYiConfig {
    /**
     * 上传路径别名
     */
    @Value("${wskj.profile}")
    private String aliasProfile;
    /**
     *
     */
    @Value("${wskj.addressEnabled}")
    private boolean aliasAddressEnabled;
    /**
     * 项目名称
     */
    @Value("${wskj.name}")
    private String aliasName;
    /**
     * 版本
     */
    @Value("${wskj.version}")
    private String aliasVersion;
    /**
     * 上传路径
     */
    @Getter
    private static String profile;
    /**
     * 获取地址开关
     */
    @Getter
    private static boolean addressEnabled;
    /**
     * 项目名称
     */
    @Getter
    private static String name;
    /**
     * 版本
     */
    @Getter
    private static String version;

    /**
     * 上传路径
     */
    @PostConstruct
    public void init() {
        profile = aliasProfile;
        addressEnabled = aliasAddressEnabled;
        name = aliasName;
        version = aliasVersion;
    }

    /**
     * 获取头像上传路径
     */
    public static String getAvatarPath() {
        return getProfile() + "/avatar";
    }

    /**
     * 获取下载路径
     */
    public static String getDownloadPath() {
        return RuoYiConfig.profile + "/download/";
    }

    /**
     * 获取上传路径
     */
    public static String getUploadPath() {
        return getProfile() + "/upload";
    }

    public static void setProfile(String profile) {
        RuoYiConfig.profile = profile;
    }
}
